package oop.controller.action.category;

import java.io.PrintWriter;
import java.util.List;

import oop.controller.action.DefaultAction;
import oop.data.CategoryWithCount;

import com.google.gson.Gson;

public class AjaxSearchAction extends DefaultAction {

	@Override
	public void perform() throws Exception {
		String prefix = request.getParameter("prefix");
		List<CategoryWithCount> categories = CategoryWithCount
				.fetchByNameIgnoreCase(prefix + "%");
		String json = new Gson().toJson(categories);
		PrintWriter out = new PrintWriter(response.getOutputStream());
		out.print(json);
		out.close();
		setPreventForward(true);
	}

}
